package com.societyGames.interceptExercises
{
import com.pblabs.engine.serialization.ISerializable;
import com.societyGames.codeExercise.CodeExercise;

public class InterceptCodeExercise extends CodeExercise implements ISerializable
{
  protected var _interceptSimulation:InterceptSimulation;
  private var _xml:XML;

  public function InterceptCodeExercise()
  {
    this._interceptSimulation = new InterceptSimulation(this._actionQueue);
    this.addChild(this._interceptSimulation.render);
  }

  //ISerializeable-->
  public function serialize(xml:XML):void
  {
    //Do nothing.
  }

  public function deserialize(xml:XML):*
  {
    _xml = xml;
    return this;
  }

  //<--ISerializable

  public override function initialize():void
  {
    super.initialize();
    this._interceptSimulation.initialize(this._xml);
  }

  public function get interceptSimulation():InterceptSimulation
  {
    return this._interceptSimulation;
  }

  //ICodeExercise-->
  protected override function evaluateWithExceptionsHandled():void
  {
    //Derived class should evaluate success
    if (this._interceptSimulation.isCaught())
    {
      _interceptSimulation.render.showFishSwim(true);
      reportSuccess();
    }
    else
    {
      _interceptSimulation.render.showFishSwim(false);
      reportFailure();
    }
  }

  //<--ICodeExercise
}
}